package com.renfei.ffmpegvideoplayer;

import android.content.Context;
import android.opengl.GLSurfaceView;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Surface;

public class VideoPlayGlSurfaceView extends GLSurfaceView {
    private static final String TAG = "VideoPlayGlSurfaceView";
    private YuvRender yuvRender;


    public VideoPlayGlSurfaceView(Context context) {
        this(context, null);
    }

    public VideoPlayGlSurfaceView(Context context, AttributeSet attrs) {
        super(context, attrs);
        setEGLContextClientVersion(2);
        yuvRender=new YuvRender(context);
        setRenderer(yuvRender);
        setRenderMode(RENDERMODE_WHEN_DIRTY);//手动渲染
        yuvRender.setOnRenderListener(new YuvRender.OnRenderListener() {
            @Override
            public void onRender() {
                Log.e(TAG, "onRender: requestRender");
                requestRender();
            }
        });

    }

    public YuvRender getYuvRender() {
        return yuvRender;
    }

    public void setYuvRenderData(int width, int height, byte[] y, byte[] u, byte[] v) {
        if (null!=yuvRender){
            yuvRender.setYuvRenderData(width, height, y, u, v);
           //    Log.e(TAG, "setYuvRenderData:  y.length ="+y.length
           //            +"  u.length   ="+u.length
           //            +"  v.length   ="+v.length
           //    );
            requestRender();
        }
    }
    
}
